home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / LSCLOSE.C < prev    next >
Text File  |  1991-09-23  |  2KB  |  87 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)lsclose.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10. #ifdef AC_STRING
  11. #include <string.h>
  12. #endif
  13.  
  14. /* library headers */
  15. #include <blkio.h>
  16.  
  17. /* local headers */
  18. #include "lseq_.h"
  19.  
  20. /*man---------------------------------------------------------------------------
  21. NAME
  22.      lsclose - close lseq
  23.  
  24. SYNOPSIS
  25.      #include <lseq.h>
  26.  
  27.      int lsclose(lsp)
  28.      lseq_t *lsp;
  29.  
  30. DESCRIPTION
  31.      The lsclose function causes any buffered data for the named lseq
  32.      to be written out, the file unlocked, and the lseq closed.
  33.  
  34.      lsclose will fail if one or more of the following is true:
  35.  
  36.      [EINVAL]       lsp is not a valid lseq pointer.
  37.      [LSENOPEN]     lsp is not open.
  38.  
  39. SEE ALSO
  40.      lscreate, lslock, lsopen, lssync.
  41.  
  42. DIAGNOSTICS
  43.      Upon successful completion, a value of 0 is returned.  Otherwise,
  44.      a value of -1 is returned, and errno set to indicate the error.
  45.  
  46. ------------------------------------------------------------------------------*/
  47. #ifdef AC_PROTO
  48. int lsclose(lseq_t *lsp)
  49. #else
  50. int lsclose(lsp)
  51. lseq_t *lsp;
  52. #endif
  53. {
  54.     /* validate arguments */
  55.     if (!ls_valid(lsp)) {
  56.         errno = EINVAL;
  57.         return -1;
  58.     }
  59.  
  60.     /* check if not open */
  61.     if (!(lsp->flags & LSOPEN)) {
  62.         errno = LSENOPEN;
  63.         return -1;
  64.     }
  65.  
  66.     /* synchronize file with buffers and unlock file */
  67.     if (lslock(lsp, LS_UNLCK) == -1) {
  68.         LSEPRINT;
  69.         return -1;
  70.     }
  71.  
  72.     /* free memory allocated for lsp */
  73.     ls_free(lsp);
  74.  
  75.     /* close lseq file */
  76.     if (bclose(lsp->bp) == -1) {
  77.         LSEPRINT;
  78.         return -1;
  79.     }
  80.  
  81.     /* scrub slot in lsb table then free it */
  82.     memset(lsp, 0, sizeof(*lsb));
  83.     lsp->flags = 0;
  84.  
  85.     return 0;
  86. }
  87.